<?php
/**	
*	FILENAME: 		/server_app/authenticate_pin.php
*	DESCRIPTION:	This script validates an existing user's pin.
*	AUTHOR:			Taylor Clifton
*	VERSION:		1.0.0
*	LAST MODIFIED:	02/15/10
**/

require_once($_SERVER['DOCUMENT_ROOT'] . "/libraries/users.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/libraries/functions.php");

$uid = $_POST["uid"];
$pin = $_POST["pin"];

if (strlen($uid) == 0 || strlen($pin) == 0) {
	$response["response_type"] = "error";
	$response["error_desc"] = "UID or PIN not provided.";
	echo(json_encode($response));	
} else {
	$encryptedPin = encryptPin($pin);
	if (authenticatePIN($uid, $encryptedPin)) {
		$response["response_type"] = "success";
		echo(json_encode($response));	
	} else {
		$response["response_type"] = "error";
		$response["error_desc"] = "Invalid PIN.";
		echo(json_encode($response));	
	}
}
?>